Page({
  data:{
    img:"",
    product_name:"",
    desc:"",
    order_id:"",
    order_number:"",
    price:"",
    shop_name:"",
    open_id:""
  },
  onLoad:function(e){
    var self=this;
    wx.showLoading();
    this.data.img=e.img;
    this.data.product_name=e.product_name;
    this.data.desc=e.desc;
    this.data.order_id=e.order_id;
    this.data.order_number=e.order_number;
    this.data.price=e.price;
    this.setData({
      img:e.img,
      product_name:e.product_name,
      desc:e.desc,
      order_number:e.order_number,
      price:e.price,
      shop_name:e.shop_name
    })
    if(e.desc=="''"){
      wx.request({
        url:"https://wx.ichelaba.com/htapi/index.php/user/order/getProductInfo",
        data:{
          product_id:e.product_id
        },
        method:"GET",
        success:function(res){
          console.log(res)
          self.setData({
            desc:res.data.desc
          })
        }
      })
    }
     wx.login({  
      success: function (loginCode) {  
        var appid = 'wxff13ea837541a1db'; //填写微信小程序appid  
        var secret = 'fa8f70abef2f0e57d9a25bd7b71cb028'; //填写微信小程序secret  
        console.log(loginCode)
        wx.request({  
          url: 'https://wx.ichelaba.com/htapi/index.php/user/user/getOpenId', 
          data:{
            code:loginCode.code
          },
          dataType:"json",
          success: function(res) { 
            console.log(res)
            self.data.open_id=res.data.openid; 
            console.log(self.data.open_id,res.openid)
            wx.hideLoading(); 
          }  
        })  
        
      }  
    })  
  },
  tap_FN:function(){
    var self=this;
    wx.request({
      url:"https://wx.ichelaba.com/htapi/index.php/store/pay/paying",
      data:{
        user_id:wx.getStorageSync("user_id"),
        id: self.data.order_id,
        openid:self.data.open_id
      },
      dataType:"json",
      method:"GET",
      success:function(res){
        wx.requestPayment({
           'timeStamp': '"' + res.data.timeStamp + '"',
           'nonceStr': '"' + res.data.nonce_str + '"',
           'package': 'prepay_id=' + res.data.prepay_id,
           'signType': 'MD5',
           'paySign': '"' + res.data.sign + '"',
           // 'paySign': '"sign=MD5(res.data.stringSignTemp).toUpperCase()'+ res.data.sign +'"',
           'success':function(r){
              console.log(r);
              console.log('success');
           },
           'fail':function(r){
              console.log(r);
              console.log('fail');
           }
        })
      }
    })
  }
})